package org.example;

public class Test2 {
    //leetcode 单词异位词
    //https://leetcode.cn/problems/valid-anagram/description/?envType=study-plan-v2&envId=top-interview-150
    public boolean isAnagram(String s, String t) {
        int[] hash = new int[26];
        for (char c : s.toCharArray()) {
            hash[c-'a']++;
        }
        for (char c : t.toCharArray()) {
            if (hash[c-'a']-- == 0) return false;
        }
        for (int i = 0; i < 26; i++) {
            if (hash[i] != 0) return false;
        }
        return true;
    }
}
